package com.framework.core.deserialize;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: Breet
 * @Date: 2018/6/13 0013 下午 2:21
 * @Description: 自定义JsonDeserialize时间格式化，用于前台字符串时间到date格式装换
 */
public class CustomDateTimeDeserialize extends JsonDeserializer<Date> {
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Override
    public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
        Date date = null;
        try {
            date = sdf.parse(jp.getText());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
